package com.itfs;

import java.util.Scanner;

public class ExceptionsDemoTest {
    public static void main(String[] args) {
        Student s = new Student();

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入姓名：");
        String name = sc.nextLine();
        s.setName(name);

        while (true) {
            System.out.println("请输入年龄：");
            String ageStr = sc.nextLine();
            try {
                int age = Integer.parseInt(ageStr);
                s.setAge(age);
                break;
            } catch (NumberFormatException e) {
                System.out.println("请输入一个整数");
                continue;
            }catch (AgeOutException e) {
                System.out.println("请输入一个符合年龄范围的数据");
                continue;
            }
        }
        System.out.println(s);

    }
}
